import server from '@/config/server/index.js'
import dictMgr from '@/biz/dict.js'
import dt from '@dt/dt'

function post(path, auth = true, config = true) {
  return server.api().post(path).auth(auth).config(config)
}

function get(path, auth = true, config = true) {
  return server.api().get(path).auth(auth).config(config)
}
let api = {
  tenantChangeLogForWeb: post('/sa-tenant/api/v1/tenant/tenantChangeLogForWeb'), //变更记录
  getUserTeam: post('/sa-tenant/api/v1/team/user/getUserTeam'), //查看人员-所属团队
  getTenantInfoByPhoneForWeb: post('/sa-tenant/api/v1/tenant/getTenantInfoByPhoneForWeb'), //变更根据手机号查询手机号信息
  saveTenantForWeb: post('/sa-tenant/api/v1/tenant/saveTenantForWeb'), //新增项目
  getPackages: post('/sa-admin/api/v1/saFunctionPackage/getPackages'), //项目包
  getSysCompanyForWeb: post('/sa-admin/api/v1/sysCompany/getSysCompanyForWeb'), //主体
  getTenantPageForWeb: post('/sa-tenant/api/v1/tenant/getTenantPageForWeb'), //项目列表
  getPackageAuthById: get('/sa-admin/api/v1/saFunctionPackage/getPackageAuthById'), //当前功能包的权限树
  deleteByTenantId: get('/sa-tenant/api/v1/tenant/deleteByTenantId'), //删除项目
  tenantDetailsForWeb: get('/sa-tenant/api/v1/tenant/tenantDetailsForWeb'), //项目详情用于编辑项目
  getTenantListByPhoneForWeb: post('/sa-tenant/api/v1/tenant/getTenantListByPhoneForWeb'), //查看人员所属组织

  tenantInformationForWeb: get('/sa-tenant/api/v1/tenant/tenantInformationForWeb'), //项目详情-项目信息
  tenantPackageForWeb: get('/sa-tenant/api/v1/tenant/tenantPackageForWeb'), //项目详情-项目套餐
  changeTenantForWeb: post('/sa-tenant/api/v1/tenant/changeTenantForWeb') //项目变更
}
function getSysCompanyForWeb(data) {
  return api.getSysCompanyForWeb.fetch(data).then((res) => {
    res.list &&
      res.list.length &&
      res.list.forEach((item) => {
        item.key = item.id
        item.value = item.companyName
      })

    console.log(res.list, '222')
    res.list.unshift({
      companyName: '不关联任何主体',
      value: '不关联任何主体',
      id: '-1',
      key: '-1'
    })
    return res.list
  })
}
function getTenantInfoByPhoneForWeb(data) {
  return api.getTenantInfoByPhoneForWeb.fetch(data)
}
function saveTenantForWeb(data) {
  return api.saveTenantForWeb.fetch(data)
}
function getPackages(data) {
  return api.getPackages.fetch(data)
}

function getTenantPageForWeb(data) {
  return api.getTenantPageForWeb.fetch(data)
}
function getPackageAuthById(data) {
  return api.getPackageAuthById.fetch(data)
}

function deleteByTenantId(data) {
  return api.deleteByTenantId.fetch(data)
}

function tenantDetailsForWeb(data) {
  return api.tenantDetailsForWeb.fetch(data)
}

function getTenantListByPhoneForWeb(data) {
  return api.getTenantListByPhoneForWeb.fetch(data)
}
function tenantInformationForWeb(data) {
  return api.tenantInformationForWeb.fetch(data)
}
function tenantPackageForWeb(data) {
  return api.tenantPackageForWeb.fetch(data)
}
function changeTenantForWeb(data) {
  return api.changeTenantForWeb.fetch(data)
}
function getUserTeam(data) {
  return api.getUserTeam.fetch(data)
}
function tenantChangeLogForWeb(data) {
  return api.tenantChangeLogForWeb.fetch(data)
}

export default {
  getTenantInfoByPhoneForWeb,
  saveTenantForWeb,
  getPackages,
  getSysCompanyForWeb,
  getTenantPageForWeb,
  getPackageAuthById,
  deleteByTenantId,
  tenantDetailsForWeb,
  getTenantListByPhoneForWeb,
  tenantInformationForWeb,
  tenantPackageForWeb,
  changeTenantForWeb,
  getUserTeam,
  tenantChangeLogForWeb
}
